package net.crowdloud.server.DatabaseAccess.user;

import java.util.ArrayList;
import java.util.List;

import javax.jdo.Extent;
import javax.jdo.PersistenceManager;
import javax.jdo.Query;

/**
 * List all the projects added in the system.
 */
public class ListUsers {

	public static List<net.crowdloud.shared.entities.User> list(
			PersistenceManager persistenceManager) {

		Extent extent = persistenceManager.getExtent(User.class, true);

		Query query;

		List<User> usersDatabase;

		query = persistenceManager.newQuery(extent);

		usersDatabase = (List<User>) query.execute("");

		List<net.crowdloud.shared.entities.User> users = new ArrayList<net.crowdloud.shared.entities.User>();

		for (User databaseUser : usersDatabase) {

			users.add(ConvertDatabaseToUser.getUser(databaseUser));
		}

		return users;
	}
}
